this.BX=this.BX||{};(function(t,e,i){"use strict";var s=function(){function t(e){var i=e.target;babelHelpers.classCallCheck(this,t);this.target=i?i:null;this.pos={top:0,left:0,x:0,y:0};this.touchInit=false;this.init()}babelHelpers.createClass(t,[{key:"init",value:function t(){if(!this.target){console.warn("BX.UI.Ears: TouchController not initialized");return}this.target.addEventListener("mousedown",this.mouseDownHandler.bind(this));this.target.addEventListener("mousemove",this.mouseMoveHandler.bind(this));this.target.addEventListener("mouseup",this.mouseUpHandler.bind(this));this.target.addEventListener("mouseleave",this.mouseUpHandler.bind(this))}},{key:"mouseDownHandler",value:function t(e){this.touchInit=true;this.target.style.cursor="grabbing";this.target.style.userSelect="none";this.target.parentNode.classList.add("--grabbing");this.pos={left:this.target.scrollLeft,top:this.target.scrollTop,x:e.clientX,y:e.clientY}}},{key:"mouseMoveHandler",value:function t(e){if(!this.touchInit){return}var i=e.clientX-this.pos.x;var s=e.clientY-this.pos.y;this.target.scrollLeft=this.pos.left-i;this.target.scrollTop=this.pos.top-s}},{key:"mouseUpHandler",value:function t(){this.touchInit=false;this.target.style.cursor="grab";this.target.style.removeProperty("user-select");this.target.parentNode.classList.remove("--grabbing")}}]);return t}();var r,o,l,n,a;var h=function(t){babelHelpers.inherits(i,t);function i(t){var s;babelHelpers.classCallCheck(this,i);s=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(i).apply(this,arguments));s.setEventNamespace("BX.UI.Ears");s.container=t.container||null;s.smallSize=t.smallSize||null;s.noScrollbar=t.noScrollbar?t.noScrollbar:false;s.className=t.className?t.className:null;s.mousewheel=t.mousewheel||null;s.touchScroll=t.touchScroll||null;s.vertical=t.vertical||null;s.itemsInShow=t.itemsInShow||null;if(s.itemsInShow){s.noScrollbar=true}s.itemSize=null;s.wrapper=null;s.leftEar=null;s.rightEar=null;s.topEar=null;s.bottomEar=null;s.parentContainer=e.Type.isDomNode(s.container)?s.container.parentNode:null;s.delay=12;s.scrollTimeout=null;s.cache=new e.Cache.MemoryCache;return s}babelHelpers.createClass(i,[{key:"bindEvents",value:function t(){this.container.addEventListener("scroll",this.toggleEars.bind(this));if(this.mousewheel){this.container.addEventListener("wheel",this.onWheel.bind(this))}if(this.vertical){if(this.itemsInShow){this.getBottomEar().addEventListener("click",this.scrollToNext.bind(this));this.getTopEar().addEventListener("click",this.scrollToPrev.bind(this))}else{this.getBottomEar().addEventListener("mouseenter",this.scrollBottom.bind(this));this.getBottomEar().addEventListener("mouseleave",this.stopScroll.bind(this));this.getBottomEar().addEventListener("mousedown",this.stopScroll.bind(this));this.getBottomEar().addEventListener("mouseup",this.scrollBottom.bind(this));this.getTopEar().addEventListener("mouseenter",this.scrollTop.bind(this));this.getTopEar().addEventListener("mouseleave",this.stopScroll.bind(this));this.getTopEar().addEventListener("mousedown",this.stopScroll.bind(this));this.getTopEar().addEventListener("mouseup",this.scrollTop.bind(this))}}if(!this.vertical){if(this.itemsInShow){this.getRightEar().addEventListener("click",this.scrollToNext.bind(this));this.getLeftEar().addEventListener("click",this.scrollToPrev.bind(this))}else{this.getLeftEar().addEventListener("mouseenter",this.scrollLeft.bind(this));this.getLeftEar().addEventListener("mouseleave",this.stopScroll.bind(this));this.getLeftEar().addEventListener("mousedown",this.stopScroll.bind(this));this.getLeftEar().addEventListener("mouseup",this.scrollLeft.bind(this));this.getRightEar().addEventListener("mouseenter",this.scrollRight.bind(this));this.getRightEar().addEventListener("mouseleave",this.stopScroll.bind(this));this.getRightEar().addEventListener("mousedown",this.stopScroll.bind(this));this.getRightEar().addEventListener("mouseup",this.scrollRight.bind(this))}}}},{key:"init",value:function t(){var e=this;if(!this.container){console.warn("BX.UI.Ears.Preview: 'container' is not defined");return}this.setWrapper();this.bindEvents();if(this.touchScroll){this.initTouchScroll()}setTimeout((function(){if(e.container.scrollWidth>e.container.offsetWidth){e.toggleRightEar();var t=e.container.querySelector('[data-role="ui-ears-active"]');t?e.scrollToActiveItem(t):null}}),600);return this}},{key:"scrollToPrev",value:function t(){if(this.vertical){this.container.scrollTo({top:this.container.scrollTop-this.getItemSize(),behavior:"smooth"})}else{this.container.scrollTo({left:this.container.scrollLeft-this.getItemSize(),behavior:"smooth"})}}},{key:"scrollToNext",value:function t(){if(this.vertical){this.container.scrollTo({top:this.container.scrollTop+this.getItemSize(),behavior:"smooth"})}else{this.container.scrollTo({left:this.container.scrollLeft+this.getItemSize(),behavior:"smooth"})}}},{key:"scrollToActiveItem",value:function t(e){var i=this;var s=e.offsetLeft-(this.container.offsetWidth/2-e.offsetWidth/2);var r=0;var o=setInterval((function(){if(r>=s||r+i.container.offsetWidth>=i.container.scrollWidth){clearInterval(o)}i.container.scrollLeft=r+=10}),10)}},{key:"onWheel",value:function t(e){var i=this;if(e.deltaY<0||e.deltaX>0){this.scrollRight()}else{this.scrollLeft()}clearTimeout(this.scrollTimeout);this.scrollTimeout=setTimeout((function(){return i.stopScroll()}),150);e.preventDefault()}},{key:"getItemSize",value:function t(){if(!this.itemSize){var e=this.container.firstElementChild;this.itemSize=this.vertical?this.container.firstElementChild.offsetHeight:this.container.firstElementChild.offsetWidth;var i=0;if(this.vertical){i=parseInt(window.getComputedStyle(e).marginTop)>parseInt(window.getComputedStyle(e).marginTop)?parseInt(window.getComputedStyle(e).marginTop):parseInt(window.getComputedStyle(e).marginBottom)}else{i=parseInt(window.getComputedStyle(e).marginLeft)+parseInt(window.getComputedStyle(e).marginRight)}if(i>0){this.itemSize=this.itemSize+i}}return this.itemSize}},{key:"setWrapper",value:function t(){this.container.classList.add("ui-ear-container");this.container.classList.add(this.vertical?"--vertical":"--horizontal");if(this.noScrollbar){this.container.classList.add("ui-ear-container-no-scrollbar")}e.Dom.append(this.getWrapper(),this.parentContainer);if(this.itemsInShow){this.container.style.setProperty(this.vertical?"height":"width",this.getItemSize()*this.itemsInShow+"px")}}},{key:"getWrapper",value:function t(){var i=this;return this.cache.remember("wrapper",(function(){return e.Tag.render(r||(r=babelHelpers.taggedTemplateLiteral(["\n\t\t\t\t\t<div class='ui-ears-wrapper "," ","'>\n\t\t\t\t\t\t","\n\t\t\t\t\t\t","\n\t\t\t\t\t\t","\n\t\t\t\t\t</div>\n\t\t\t\t"])),i.smallSize?" ui-ears-wrapper-sm":"",i.className?i.className:"",i.vertical?i.getTopEar():i.getLeftEar(),i.vertical?i.getBottomEar():i.getRightEar(),i.container)}))}},{key:"getTopEar",value:function t(){return this.cache.remember("topEar",(function(){return e.Tag.render(o||(o=babelHelpers.taggedTemplateLiteral(["\n\t\t\t\t\t<div class='ui-ear ui-ear-top'></div>\n\t\t\t\t"])))}))}},{key:"getBottomEar",value:function t(){return this.cache.remember("bottomEar",(function(){return e.Tag.render(l||(l=babelHelpers.taggedTemplateLiteral(["\n\t\t\t\t\t<div class='ui-ear ui-ear-bottom'></div>\n\t\t\t\t"])))}))}},{key:"getLeftEar",value:function t(){return this.cache.remember("leftEar",(function(){return e.Tag.render(n||(n=babelHelpers.taggedTemplateLiteral(["\n\t\t\t\t\t<div class='ui-ear ui-ear-left'></div>\n\t\t\t\t"])))}))}},{key:"getRightEar",value:function t(){return this.cache.remember("rightEar",(function(){return e.Tag.render(a||(a=babelHelpers.taggedTemplateLiteral(["\n\t\t\t\t\t<div class='ui-ear ui-ear-right'></div>\n\t\t\t\t"])))}))}},{key:"toggleEars",value:function t(){if(this.vertical){this.toggleTopEar();this.toggleBottomEar()}else{this.toggleRightEar();this.toggleLeftEar()}}},{key:"toggleTopEar",value:function t(){if(this.container.scrollTop>0){this.getTopEar().classList.add("ui-ear-show")}else{this.getTopEar().classList.remove("ui-ear-show")}}},{key:"toggleBottomEar",value:function t(){if(this.container.scrollHeight>this.container.offsetHeight&&Math.ceil(this.container.offsetHeight+this.container.scrollTop)<this.container.scrollHeight){this.getBottomEar().classList.add("ui-ear-show")}else{this.getBottomEar().classList.remove("ui-ear-show")}}},{key:"toggleRightEar",value:function t(){if(this.container.scrollWidth>this.container.offsetWidth&&Math.ceil(this.container.offsetWidth+this.container.scrollLeft)<this.container.scrollWidth){this.getRightEar().classList.add("ui-ear-show")}else{this.getRightEar().classList.remove("ui-ear-show")}}},{key:"toggleLeftEar",value:function t(){if(this.container.scrollLeft>0){this.getLeftEar().classList.add("ui-ear-show")}else{this.getLeftEar().classList.remove("ui-ear-show")}}},{key:"scrollTop",value:function t(){console.log("scrollTop");this.stopScroll("bottom");var e=this.container.scrollTop;this.container.scrollTop-=10;this.emit("onEarsAreMoved");if(this.container.scrollTop<=10){this.emit("onEarsAreHidden")}this.setDelay();this.scrollInterval=setInterval(this.scrollTop.bind(this),this.delay);this.top=true}},{key:"scrollBottom",value:function t(){console.log("scrollBottom");this.stopScroll("top");var e=this.container.scrollTop;this.container.scrollTop+=10;this.emit("onEarsAreMoved");if(this.container.scrollTop>=0&&e<0){this.emit("onEarsAreHidden")}this.setDelay();this.scrollInterval=setInterval(this.scrollBottom.bind(this),this.delay);this.bottom=true}},{key:"scrollLeft",value:function t(){this.stopScroll("right");var e=this.container.scrollLeft;this.container.scrollLeft-=10;this.emit("onEarsAreMoved");if(this.container.scrollLeft<=0&&e>0){this.emit("onEarsAreHidden")}this.setDelay();this.scrollInterval=setInterval(this.scrollLeft.bind(this),this.delay);this.left=true}},{key:"scrollRight",value:function t(){this.stopScroll("left");this.container.scrollLeft+=10;this.emit("onEarsAreMoved");if(this.container.scrollLeft<=10){this.emit("onEarsAreShown")}this.setDelay();this.scrollInterval=setInterval(this.scrollRight.bind(this),this.delay);this.right=true}},{key:"setDelay",value:function t(){if(this.container.scrollWidth<this.container.offsetWidth*1.6){this.delay=20;return}var e=this.container.scrollWidth-this.container.offsetWidth;var i=this.container.scrollLeft>e/1.3;var s=this.container.scrollLeft<e/4;if(this.container.scrollLeft===e){this.delay=12}if(this.left){if(s){this.delay=25}else{this.delay=12}}if(this.right){if(i){this.delay=25}else{this.delay=12}}}},{key:"stopScroll",value:function t(e){if(this.scrollInterval){clearInterval(this.scrollInterval);this.scrollInterval=0}if(e==="right"){this.right=false}else if(e==="left"){this.left=false}else if(e==="bottom"){this.bottom=false}else if(e==="top"){this.top=false}}},{key:"initTouchScroll",value:function t(){new s({target:this.container})}}]);return i}(i.EventEmitter);t.Ears=h})(this.BX.UI=this.BX.UI||{},BX,BX.Event);
//# sourceMappingURL=ears.bundle.map.js